import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
 export const formStorage = defineStore('FormStorage',()=>{
    const form=ref({
        registerId:0,
        readme:null,
        present:null,
        presentTreat:null,
        history:null,
        allergy:null,
        physique:null,
        proposal:null,
        careful:null,
        diagnosis:null,
        cure:null
    });
    const setForm = (newForm:any) => {
        form.value = {
                registerId:newForm.registerId,
                readme:newForm.readme,
                present:newForm.present,
                presentTreat:newForm.presentTreat,
                history:newForm.history,
                allergy:newForm.allergy,
                physique:newForm.physique,
                proposal:newForm.proposal,
                careful:newForm.careful,
                diagnosis:newForm.diagnosis,
                cure:newForm.cure
        };
        // 强制更新 sessionStorage
        storage();
    };
    
    // storage 函数
    const storage = () => {
        sessionStorage.setItem('form', JSON.stringify(form.value)); // 使用 Form.value
    };
    
    
    return {
        form,
      setForm
    }
 })                       